package com.gp.pj.mapper;

import com.gp.pj.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gp.pj.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Chloe
 * @since 2020-12-07
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 登录操作
     * @param userName
     * @param password
     * @return
     */
    Map<String,UserVo> login(@Param("userName")String userName,@Param("password")String password);

    /**
     * 查询是否有这个用户
     * @param userName
     * @return
     */
    @Select("select * from t_user where name = #{userName}")
    Integer checkUser(@Param("userName")String userName);

    /**
     * 查询用户信息
     * @param userId
     * @return
     */
    @Select("select r.name as accesses from t_user_role ur " +
            "left join t_role r on ur.role_id = r.id where ur.user_id = #{userId}")
    List<UserVo> getUserInfo(@Param("userId") String userId);

    @Select("select u.id as userId,u.name as userName,e.id as empId,e.name as empName,u.password as password,e.type as type,u.status as status,GROUP_CONCAT( r.name ) AS accesses from t_user u " +
            "left join t_employee e on e.id = u.emp_id left join t_user_role ur on ur.user_id = u.id left join t_role r on r.id = ur.role_id group by u.id")
    List<UserVo> getUserList();


}
